package cz.cvut.fel.gfupan.gui;

import cz.cvut.fel.gfupan.gui.component.AutoCompleteBox;
import cz.cvut.fel.gfupan.gui.action.AboutAction;
import cz.cvut.fel.gfupan.gui.action.ExitAction;
import cz.cvut.fel.gfupan.gui.action.FindAction;
import cz.cvut.fel.gfupan.gui.action.NewAction;
import cz.cvut.fel.gfupan.gui.action.OpenAction;
import cz.cvut.fel.gfupan.gui.action.SaveAction;
import cz.cvut.fel.gfupan.gui.action.SaveAsAction;
import cz.cvut.fel.gfupan.gui.util.AutoCompleteItem;
import cz.cvut.fel.gfupan.gui.util.AutoCompleteList;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public final class Window extends javax.swing.JFrame implements KeyEventDispatcher {

    private javax.swing.JButton currentButton = null;
    private MeasurePanel measures[];
    private OverviewPanel overview;
    private StartupWindow startup;

    /**
     * Creates new form Window
     */
    public Window() {
        super.setVisible(false);
        initComponents();
        autoCompleteBox();

        setLocationRelativeTo(null);

        setActionListeners();

        addWindowListener(new ExitAction(this));


        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(this);
        this.setFocusable(true);

        startup = new StartupWindow(this, true);
        startup.setVisible(false);

        measures = new MeasurePanel[6];
        for (int i = 0; i < 6; ++i) {
            measures[i] = new MeasurePanel(i);
        }
        overview = new OverviewPanel();

    }

    @Override
    public void setVisible(boolean bln) {
        super.setVisible(bln);
        startup.setVisible(bln);
    }

    public void clearWindow() {
        for (int i = 0; i < 6; ++i) {
            measures[i].clearAll();
        }

        overview = new OverviewPanel();

        if (currentButton != null) {
            currentButton.setIcon(null); // NOI18N
        }

        mainPanel.removeAll();
        mainPanel.updateUI();
    }

    private void setActionListeners() {
        //menu - File
        newMenuItem.addActionListener(new NewAction(null));
        openMenuItem.addActionListener(new OpenAction(null));
        saveMenuItem.addActionListener(new SaveAction(null));
        saveAsMenuItem.addActionListener(new SaveAsAction(null));
        exitMenuItem.addActionListener(new ExitAction(this));

        //menu - Help
        aboutMenuItem.addActionListener(new AboutAction());

        //toolbar action listeners
        newToolBarItem.addActionListener(new NewAction(null));
        openToolBarItem.addActionListener(new OpenAction(null));
        saveToolBarItem.addActionListener(new SaveAction(null));


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolBar = new javax.swing.JToolBar();
        newToolBarItem = new javax.swing.JButton();
        openToolBarItem = new javax.swing.JButton();
        saveToolBarItem = new javax.swing.JButton();
        separatorToolBarItem = new javax.swing.JToolBar.Separator();
        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        viewMeasure1Button = new javax.swing.JButton();
        viewMeasure2Button = new javax.swing.JButton();
        viewMeasure3Button = new javax.swing.JButton();
        viewMeasure4Button = new javax.swing.JButton();
        viewMeasure5Button = new javax.swing.JButton();
        viewMeasure6Button = new javax.swing.JButton();
        overviewButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        separatorFileMenu = new javax.swing.JPopupMenu.Separator();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        separator2FileMenu = new javax.swing.JPopupMenu.Separator();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/cvut/fel/gfupan/res/Bundle"); // NOI18N
        setTitle(bundle.getString("Window.title")); // NOI18N
        setMinimumSize(new java.awt.Dimension(500, 400));
        setName("WindowFrame"); // NOI18N

        toolBar.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        toolBar.setFloatable(false);
        toolBar.setRollover(true);
        toolBar.setMaximumSize(new java.awt.Dimension(60, 36));
        toolBar.setMinimumSize(new java.awt.Dimension(60, 36));

        newToolBarItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/24/new.png"))); // NOI18N
        newToolBarItem.setText(bundle.getString("Window.newToolBarItem.text")); // NOI18N
        newToolBarItem.setToolTipText(bundle.getString("Window.newToolBarItem.toolTipText")); // NOI18N
        newToolBarItem.setFocusable(false);
        newToolBarItem.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        newToolBarItem.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(newToolBarItem);

        openToolBarItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/24/open.png"))); // NOI18N
        openToolBarItem.setText(bundle.getString("Window.openToolBarItem.text")); // NOI18N
        openToolBarItem.setToolTipText(bundle.getString("Window.openToolBarItem.toolTipText")); // NOI18N
        openToolBarItem.setFocusable(false);
        openToolBarItem.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openToolBarItem.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(openToolBarItem);

        saveToolBarItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/24/save.png"))); // NOI18N
        saveToolBarItem.setText(bundle.getString("Window.saveToolBarItem.text")); // NOI18N
        saveToolBarItem.setToolTipText(bundle.getString("Window.saveToolBarItem.toolTipText")); // NOI18N
        saveToolBarItem.setFocusable(false);
        saveToolBarItem.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveToolBarItem.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(saveToolBarItem);
        toolBar.add(separatorToolBarItem);

        mainPanel.setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText(bundle.getString("Window.jLabel1.text")); // NOI18N
        jPanel1.add(jLabel1);

        viewMeasure1Button.setText(bundle.getString("Window.viewMeasure1Button.text")); // NOI18N
        viewMeasure1Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure1Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure1Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure1Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure1ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure1Button);

        viewMeasure2Button.setText(bundle.getString("Window.viewMeasure2Button.text")); // NOI18N
        viewMeasure2Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure2Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure2Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure2Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure2ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure2Button);

        viewMeasure3Button.setText(bundle.getString("Window.viewMeasure3Button.text")); // NOI18N
        viewMeasure3Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure3Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure3Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure3Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure3ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure3Button);

        viewMeasure4Button.setText(bundle.getString("Window.viewMeasure4Button.text")); // NOI18N
        viewMeasure4Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure4Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure4Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure4Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure4ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure4Button);

        viewMeasure5Button.setText(bundle.getString("Window.viewMeasure5Button.text")); // NOI18N
        viewMeasure5Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure5Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure5Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure5Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure5ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure5Button);

        viewMeasure6Button.setText(bundle.getString("Window.viewMeasure6Button.text")); // NOI18N
        viewMeasure6Button.setMaximumSize(new java.awt.Dimension(67, 23));
        viewMeasure6Button.setMinimumSize(new java.awt.Dimension(67, 23));
        viewMeasure6Button.setPreferredSize(new java.awt.Dimension(67, 23));
        viewMeasure6Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewMeasure6ButtonActionPerformed(evt);
            }
        });
        jPanel1.add(viewMeasure6Button);

        overviewButton.setText(bundle.getString("Window.overviewButton.text")); // NOI18N
        overviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                overviewButtonActionPerformed(evt);
            }
        });
        jPanel1.add(overviewButton);

        fileMenu.setMnemonic('s');
        fileMenu.setText(bundle.getString("Window.fileMenu.text")); // NOI18N

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/new.png"))); // NOI18N
        newMenuItem.setText(bundle.getString("Window.newMenuItem.text")); // NOI18N
        fileMenu.add(newMenuItem);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/open.png"))); // NOI18N
        openMenuItem.setMnemonic('o');
        openMenuItem.setText(bundle.getString("Window.openMenuItem.text")); // NOI18N
        fileMenu.add(openMenuItem);
        fileMenu.add(separatorFileMenu);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/save.png"))); // NOI18N
        saveMenuItem.setMnemonic('s');
        saveMenuItem.setText(bundle.getString("Window.saveMenuItem.text")); // NOI18N
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/save_as.png"))); // NOI18N
        saveAsMenuItem.setMnemonic('a');
        saveAsMenuItem.setText(bundle.getString("Window.saveAsMenuItem.text")); // NOI18N
        fileMenu.add(saveAsMenuItem);
        fileMenu.add(separator2FileMenu);

        exitMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/exit.png"))); // NOI18N
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText(bundle.getString("Window.exitMenuItem.text")); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText(bundle.getString("Window.helpMenu.text")); // NOI18N

        aboutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/about.png"))); // NOI18N
        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText(bundle.getString("Window.aboutMenuItem.text")); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void viewMeasure6ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure6ButtonActionPerformed
        showMeasurePanelId(6);
    }//GEN-LAST:event_viewMeasure6ButtonActionPerformed

    private void viewMeasure4ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure4ButtonActionPerformed
        showMeasurePanelId(4);
    }//GEN-LAST:event_viewMeasure4ButtonActionPerformed

    private void viewMeasure1ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure1ButtonActionPerformed
        showMeasurePanelId(1);
    }//GEN-LAST:event_viewMeasure1ButtonActionPerformed

    private void viewMeasure2ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure2ButtonActionPerformed
        showMeasurePanelId(2);
    }//GEN-LAST:event_viewMeasure2ButtonActionPerformed

    private void viewMeasure3ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure3ButtonActionPerformed
        showMeasurePanelId(3);
    }//GEN-LAST:event_viewMeasure3ButtonActionPerformed

    private void viewMeasure5ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewMeasure5ButtonActionPerformed
        showMeasurePanelId(5);
    }//GEN-LAST:event_viewMeasure5ButtonActionPerformed

    private void overviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_overviewButtonActionPerformed
        showOverviewPanel();
    }//GEN-LAST:event_overviewButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JButton newToolBarItem;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JButton openToolBarItem;
    private javax.swing.JButton overviewButton;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JButton saveToolBarItem;
    private javax.swing.JPopupMenu.Separator separator2FileMenu;
    private javax.swing.JPopupMenu.Separator separatorFileMenu;
    private javax.swing.JToolBar.Separator separatorToolBarItem;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JButton viewMeasure1Button;
    private javax.swing.JButton viewMeasure2Button;
    private javax.swing.JButton viewMeasure3Button;
    private javax.swing.JButton viewMeasure4Button;
    private javax.swing.JButton viewMeasure5Button;
    private javax.swing.JButton viewMeasure6Button;
    // End of variables declaration//GEN-END:variables
    private AutoCompleteBox searchToolBarItem;

    private void showMeasurePanelId(int id) {
        setButtonImage(id);
        mainPanel.removeAll();
        mainPanel.add(measures[id - 1]);
        measures[id - 1].moveToTab(0);
        mainPanel.updateUI();
    }

    private void showOverviewPanel() {
        setButtonImage(7);
        mainPanel.removeAll();
        mainPanel.add(overview);
        mainPanel.updateUI();
        overview.setValue();
    }

    public void showElementByMeasureAndId(int measure, int tab, int id) {
        setButtonImage(measure);
        mainPanel.removeAll();

        if (measure > 0 && measure < AutoCompleteList.OVERVIEW_MEASURE) {
            MeasurePanel mes = measures[measure - 1];
            mainPanel.add(mes);
            mes.moveToTabAndRow(tab, id);
        } else if (measure == AutoCompleteList.OVERVIEW_MEASURE) {
            mainPanel.add(overview);
        }

        mainPanel.updateUI();

    }

    private void autoCompleteBox() {
        searchToolBarItem = new AutoCompleteBox(this, AutoCompleteList.getList());
        searchToolBarItem.setAutoscrolls(false);
        searchToolBarItem.setMaximumSize(new java.awt.Dimension(200, 20));
        toolBar.add(searchToolBarItem);
        
        final Window win = this;

        javax.swing.JButton findButton = new javax.swing.JButton();
        findButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/find2.png"))); // NOI18N
        findButton.setText(""); // NOI18N
        findButton.setFocusable(true);
        findButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        findButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        
        findButton.addActionListener(new FindAction(searchToolBarItem));
        findButton.addKeyListener(new FindAction(searchToolBarItem));

        toolBar.add(findButton);
    }

    private void setButtonImage(int id) {
        if (currentButton != null) {
            currentButton.setIcon(null); // NOI18N
        }

        switch (id) {
            case 1:
                currentButton = viewMeasure1Button;
                break;
            case 2:
                currentButton = viewMeasure2Button;
                break;
            case 3:
                currentButton = viewMeasure3Button;
                break;
            case 4:
                currentButton = viewMeasure4Button;
                break;
            case 5:
                currentButton = viewMeasure5Button;
                break;
            case 6:
                currentButton = viewMeasure6Button;
                break;
            case 7:
                currentButton = overviewButton;
                break;
            default:
                return;
        }

        currentButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/gfupan/res/16/preferences.png"))); // NOI18N
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent e) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            if (e.getKeyCode() == KeyEvent.VK_F1) {
                showMeasurePanelId(1);
            } else if (e.getKeyCode() == KeyEvent.VK_F2) {
                showMeasurePanelId(2);
            } else if (e.getKeyCode() == KeyEvent.VK_F3) {
                showMeasurePanelId(3);
            } else if (e.getKeyCode() == KeyEvent.VK_F4) {
                showMeasurePanelId(4);
            } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                showMeasurePanelId(5);
            } else if (e.getKeyCode() == KeyEvent.VK_F6) {
                showMeasurePanelId(6);
            } else if (e.getKeyCode() == KeyEvent.VK_F7) {
                showOverviewPanel();
            } else if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
                searchToolBarItem.requestFocus();
            }
        }
        return false;
    }
    /**
     * @param args the command line arguments
     */
    public static Splash splash;

    public static void main(String args[]) {
        try {
            // Set cross-platform Java L&F (also called "Metal")
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }

        splash = new Splash();
        splash.setVisible(true);

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Session.getInstance().window = new Window();
                Session.getInstance().window.setVisible(true);

                splash.dispose();
            }
        });
    }
}
